package APIs.twitter;

import java.util.Vector;

public class APITest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {  		
				if(args.length == 5 && (args[0].equalsIgnoreCase("-upload") || args[0].equalsIgnoreCase("-u"))) {
					TwitterLink.uploadImage(args[1],args[2],args[3],args[4]);
				} else if (args.length == 3 && args[0].equalsIgnoreCase("-downloadall")) {
					TwitterLink.downloadImages(args[1], args[2], false);
				} else if (args.length == 3 && (args[0].equalsIgnoreCase("-downloadnew") || args[0].equalsIgnoreCase("-d"))) {
					TwitterLink.downloadImages(args[1], args[2], true);
				} else if(args.length > 0 && args[0].equalsIgnoreCase("-help")){
					printUsage();
				} else if(args.length > 0 && args[0].equalsIgnoreCase("-getallfilenames")){
					Vector<String> files = TwitterLink.downloadImageNames(args[1],false);
					
					for(int i = 0; i < files.size(); i++) {
						System.out.println(files.get(i));
					}
				} else if(args.length > 0 && args[0].equalsIgnoreCase("-getnewfilenames")){
					Vector<String> files = TwitterLink.downloadImageNames(args[1],true);
					
					for(int i = 0; i < files.size(); i++) {
						// only output the name of new files
						if(FileManipulation.isNewFile(files.get(i), args[1])) {
							System.out.println(files.get(i));
						}
					}
				} else if(args.length > 0 && args[0].equalsIgnoreCase("-reinventory")){
					FileManipulation.writeImageToDisk(args[1], args[2], TwitterLink.parseFiletype(args[1]),args[3]);
				} else if(args.length > 0 && args[0].equalsIgnoreCase("-new")){
					System.out.println(FileManipulation.isNewFile(args[1], args[2]));
				} else {
					printUsage();
				}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void printUsage() {
		System.out.println("Usage: twitter.jar");
		System.out.println("\t-upload <username> <password> <file path> <status msg>");
		System.out.println("\t-downloadall <username> <download path>");
		System.out.println("\t-downloadnew <username> <download path>");
		System.out.println("\t-getallfilenames <username>");
		System.out.println("\t-getnewfilenames <username>");
		System.out.println("\t-reinventory <image link> <download path> <Twitter Handle>"); // manually download a file
		System.out.println("\t-new <filename> <username>"); // is the provided filename a new file
	}
}
